﻿#include "IBelt.h"
#include <QDebug>
#include "CPublicData.h"
#include "CHeader.h"
// 创建设备实例
DEVICE_EXPORT IDevice* createDevice(SDeviceConfig* pDevice)
{
	return new IBelt(pDevice);  // 创建并返回一个 Robot 实例
}

DEVICE_EXPORT QVector<IDevice*>* createDevices(SDeviceConfig* pDevice)
{
	QVector<IDevice*>* vecDevice = new QVector<IDevice*>();
	IDevice* pDev = new IBelt(pDevice);
	vecDevice->push_back(pDev);
	return vecDevice;
}
// 销毁设备实例
DEVICE_EXPORT void destroyDevice(IDevice* dev) 
{
	if (dev) 
	{
		delete dev;  // 删除设备实例
	}
}

DEVICE_EXPORT QVector<QString>* getModelList()
{
	static QVector<QString> modelList = { "BLT-RD-A1"};
	return &modelList;
}

DEVICE_EXPORT QVector<QWidget*>* getPublicCardList()
{
	QVector<QWidget*>* vecWidget = new QVector<QWidget*>();
	return vecWidget;
}
DEVICE_EXPORT QWidget* getPublicCard(int nCardId, QString* psCardGuid)
{
	QWidget* pWidget = new QWidget();
	return pWidget;
}


// 构造函数
IBelt::IBelt()
{
}

IBelt::IBelt(SDeviceConfig * pDeviceConfig)
{
	m_pDeviceConfig = pDeviceConfig;
	if (!CPublicData::instance().m_bSqlInit)
	{
		CPublicData::instance().m_bSqlInit = CPublicData::instance().initSql();
		CPublicData::instance().m_pSqlDllOper->startWork();
		QThread::msleep(300);
	}
	m_pBelt = new Belt(pDeviceConfig->sDeviceName, pDeviceConfig->sDeviceId, pDeviceConfig->sConfig);
}

// 析构函数
IBelt::~IBelt() 
{
	if (m_pBelt)
	{
		delete m_pBelt;
		m_pBelt = nullptr;
	}
}

QObject * IBelt::getDeviceObject()
{
	return nullptr;
}

bool IBelt::startDevice()
{
	return m_pBelt->startDevice();
}

void IBelt::stopDevice()
{
	m_pBelt->stopDevice();
}

bool IBelt::controlDevice(const QString & cmd)
{
	return false;
}

//删除设备
void IBelt::deleteDevice()
{

 }

QString IBelt::getDeviceStatus() const
{
	return QString();
}

QList<CMeasurePoint*> IBelt::getMeasurePoints() const
{
	return m_pBelt->getMeasurePoints();
}

void IBelt::setAlarmArea(const QString & area)
{
}

QList<QString> IBelt::getDeviceLogs() const
{
	return QList<QString>();
}

QWidget * IBelt::getDeviceConfigUi()
{
	return m_pBelt->getDeviceConfigUi();
}

QWidget * IBelt::getDeviceRunUi()
{
	return m_pBelt->getMainUi();
}

QWidget * IBelt::getDeviceThumbnailUi(int nId)
{
	return m_pBelt->getPanel(nId);
}

QVector<QWidget*> IBelt::getDeviceUiList()
{
	return m_pBelt->getPanelList();
}

QMap<QString, QString> IBelt::getInputPointList()
{
	return m_pBelt->getInputPointList();
}


void IBelt::setInputPointList(QMap<QString, CMeasurePoint*> vecInputPoint)
{
	//QString sAdd = vecInputPoint[0]->getCompletepath();
	m_pBelt->setInputPoint(vecInputPoint);
}

